package com.itmk.web.userInfo.service.impl;


import java.util.Base64;
import java.util.List;

import com.itmk.web.userInfo.entity.*;
import com.itmk.web.userInfo.mapper.UserInfoMapper;
import com.itmk.web.userInfo.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserInfoServiceImpl implements UserInfoService {

    //加盐
    private static final String B64 = "...ASEDcdthvfdWERVDDGHBfdrhgdjbfdr";

    @Autowired
    UserInfoMapper userInfoMaper;

    @Override
    public BasicInfo getBasicInfo(String uuid) {
        return userInfoMaper.getBasicInfo(uuid);
    }

    @Override
    public EducationInfo getEducationInfo(String uuid) {
        return userInfoMaper.getEducationInfo(uuid);
    }

    @Override
    public ForjobInfo getForJobInfo(String uuid) {

        NewForjobInfo newForjobInfo =  userInfoMaper.getForJobInfo(uuid);
        ForjobInfo forjobInfo = new ForjobInfo();
        forjobInfo.setIdentity(newForjobInfo.getIdentity());
        forjobInfo.setFirstJobTime(newForjobInfo.getFirstJobTime());
        forjobInfo.setStatus(newForjobInfo.getStatus());
        forjobInfo.setCity(newForjobInfo.getCity());
        forjobInfo.setPosition(newForjobInfo.getPosition());
        forjobInfo.setAdvantage(newForjobInfo.getAdvantage());
        forjobInfo.setUuid(newForjobInfo.getUuid());
        forjobInfo.setForType(newForjobInfo.getForType());

        Salary salary = new Salary();
        salary.setMsalaryMax(newForjobInfo.getMsalaryMax());
        salary.setMsalaryMin(newForjobInfo.getMsalaryMin());
        salary.setNumMouth(newForjobInfo.getNumMouth());
        salary.setDsalaryMax(newForjobInfo.getDsalaryMax());
        salary.setDsalaryMin(newForjobInfo.getDsalaryMin());
        forjobInfo.setSalary(salary);

        List<JobExperience> je = userInfoMaper.getJe(uuid);
        for (JobExperience jobExperience : je) {
            Time time = new Time();
            time.setStart(jobExperience.getTimeStart());
            time.setEnd(jobExperience.getTimeEnd());
            jobExperience.setTime(time);
        }
        forjobInfo.setJobExperience(je);

        List<ProjectExperience> pe = userInfoMaper.getPe(uuid);
        for (ProjectExperience projectExperience : pe) {
            Time time = new Time();
            time.setStart(projectExperience.getTimeStart());
            time.setEnd(projectExperience.getTimeEnd());
            projectExperience.setTime(time);
        }
        forjobInfo.setProjectExperiences(pe);
        return forjobInfo;
    }

    @Override
    public Boolean updateBasicInfo(BasicInfo basicInfo,String uuid) {
        if (basicInfo.getPassword()!=null) {
            //对密码进行加密
            String pwCode = Base64.getEncoder().encodeToString((basicInfo.getPassword()+B64).getBytes());
            basicInfo.setPassword(pwCode);
            //再对User表进行修改密码
            userInfoMaper.updatePassword(pwCode,uuid);
        }
        return userInfoMaper.updateBasicInfo(basicInfo,uuid);
    }

    @Override
    public Boolean updateEdI(NewEducation edi, String uuid) {
        return userInfoMaper.updateEducationInfo(edi,uuid);
    }

    @Override
    public Boolean updateFji(ForjobInfo fji, String uuid) {
        return userInfoMaper.updateForjobInfo(fji,uuid);
    }

    @Override
    public void updateLogo(String fileName, String uuid) {
        userInfoMaper.updateUserLogo(fileName,uuid);
    }

    @Override
    public TokenUUID getTokenUUID(String uuid) {
        return userInfoMaper.getTokenUUID(uuid);
    }

    @Override
    public String checkFile(String uuid) {
        return userInfoMaper.checkFile(uuid);
    }

    @Override
    public Boolean addJe(JobExperience je, String uuid) {
        return userInfoMaper.addJe(je,uuid);
    }

    @Override
    public Boolean addPe(ProjectExperience pe, String uuid) {
        return userInfoMaper.addPe(pe,uuid);
    }

    @Override
    public Boolean delJeById(Long id,String uuid) {
        return userInfoMaper.delJeById(id,uuid);
    }

    @Override
    public Boolean delPeById(Long id, String uuid) {
        return userInfoMaper.delPeById(id,uuid);
    }

    @Override
    public Boolean updJeById(JobExperience je, String uuid) {
        return userInfoMaper.updJeById(je,uuid);
    }

    @Override
    public Boolean updPeById(ProjectExperience pe, String uuid) {
        return userInfoMaper.updPeById(pe,uuid);
    }

    @Override
    public String checkResume(String uuid) {
        return userInfoMaper.checkResume(uuid);
    }

    @Override
    public void updateLinkPDF(String fileName, String uuid) {
        userInfoMaper.updateLinkPDF(fileName,uuid);
    }
}
